
import json

#准备一个列表，列表里面的每一个元素都是字典，将其转换为json
data=[{"name":"吴彦祖","age":11},{"name":"陈冠希","age":21},{"name":"郑金贵","age":29}]

# json_str=json.dumps(data)#这个得到的字符串是asic
json_str=json.dumps(data,ensure_ascii=False)

print(type(json_str))
print(json_str)

data1={"name":"周杰伦","addr":"台北"}
json_str2=json.dumps(data1,ensure_ascii=False)

print(type(json_str2))
print(json_str2)

#将json字符串转换为python数据类型
s='[{"name":"吴彦祖","age":11},{"name":"陈冠希","age":21},{"name":"郑金贵","age":29}]'
l=json.loads(s)
print(type(l))
print(l)

s2='{"name":"周杰伦","addr":"台北"}'
l2=json.loads(s2)
print(type(l2))
print(l2)